//
//  CTUserSubjectCell.m
//  ConstellationTalk_0.1
//
//  Created by 韩威 on 15/5/25.
//  Copyright (c) 2015年 riley chu. All rights reserved.
//

#import "CTUserSubjectCell.h"
#import "CTDebugManager.h"
#import "CTAppLanguage.h"
#import "CTRequestUtil.h"

@interface CTUserSubjectCell ()
{
    UIImageView * picImageView;
    UILabel * nameLabel;
    
    UILabel * trendsLabel;
    UILabel * originLabel;
    UILabel * describeLabel;
    
    UIImageView * trendsImageView;
    UIImageView * originImageView;
    UIImageView * describeImageView;
}

@end

@implementation CTUserSubjectCell
- (void)dealloc
{
    [picImageView removeFromSuperview];
    picImageView = nil;
    [nameLabel removeFromSuperview];
    nameLabel = nil;
    [trendsImageView removeFromSuperview];
    trendsImageView = nil;
    [originImageView removeFromSuperview];
    originImageView = nil;
    [describeImageView removeFromSuperview];
    describeImageView = nil;
    [trendsLabel removeFromSuperview];
    trendsLabel = nil;
    [originLabel removeFromSuperview];
    originLabel = nil;
    [describeLabel removeFromSuperview];
    describeLabel = nil;
    
    [CTDebugManager showDebugLogInfo:@"dealloc : CTUserPublishCollectionCell Is Removed!!!"];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        picImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, 100)];
        picImageView.layer.cornerRadius = 3;
        picImageView.layer.masksToBounds = YES;
        picImageView.backgroundColor = [UIColor clearColor];
        [self addSubview:picImageView];
        
        nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 115, frame.size.width, 15)];
        nameLabel.font = [UIFont systemFontOfSize:15];
        nameLabel.textColor = [UIColor colorWithRed:102/255.0 green:102/255.0  blue:102/255.0  alpha:1.0];
        [self addSubview:nameLabel];
        
        
        trendsImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 140, 38, 18)];
        trendsImageView.image = [UIImage imageNamed:@"tag_one"];
        trendsImageView.backgroundColor = [UIColor clearColor];
        [self addSubview:trendsImageView];
        
        originImageView = [[UIImageView alloc] initWithFrame:CGRectMake(trendsImageView.frame.size.width+10,140, 38, 18)];
        originImageView.image = [UIImage imageNamed:@"tag_two"];
        originImageView.backgroundColor = [UIColor clearColor];
        [self addSubview:originImageView];
        
        
        describeImageView = [[UIImageView alloc] initWithFrame:CGRectMake( originImageView.frame.size.width+trendsImageView.frame.size.width+20,140, 58, 18)];
        describeImageView.image = [UIImage imageNamed:@"tag_three"];
        describeImageView.backgroundColor = [UIColor clearColor];
        [self addSubview:describeImageView];
        
        
        trendsLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 38, 18)];
        trendsLabel.font = [UIFont systemFontOfSize:14];
        trendsLabel.textAlignment = NSTextAlignmentCenter;
        trendsLabel.textColor = [UIColor colorWithRed:254/255.0 green:182/255.0 blue:130/255.0 alpha:1.0];
        [trendsImageView addSubview:trendsLabel];
        
        originLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,0, 38, 18)];
        originLabel.font = [UIFont systemFontOfSize:14];
        originLabel.textAlignment = NSTextAlignmentCenter;
        originLabel.textColor = [UIColor colorWithRed:163/255.0 green:227/255.0 blue:216/255.0 alpha:1.0];
        [originImageView addSubview:originLabel];
        
        describeLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,0, 58, 18)];
        describeLabel.font = [UIFont systemFontOfSize:14];
        describeLabel.textAlignment = NSTextAlignmentCenter;
        describeLabel.textColor = [UIColor colorWithRed:255/255.0 green:225/255.0 blue:114/255.0 alpha:1.0];
        [describeImageView addSubview:describeLabel];
    }
    return self;
}


#pragma mark - setter -

-(void)setImgUrl:(NSString *)imgUrl
{
    [CTRequestUtil requestImgWithUrl:imgUrl withCompletionSuccessHandler:^(UIImage *img) {
        picImageView.image = img;
    } withFailedHandler:^(NSError *error) {
        
    }];
}
-(void)setDescribe:(NSString *)describe
{
    describeLabel.text = describe;
}
-(void)setName:(NSString *)name
{
    nameLabel.text = name;
}
-(void)setOrigin:(BOOL)isOfficial
{
    if (isOfficial == YES) {
        originImageView.hidden = NO;
        originLabel.text = [CTAppLanguage localizedStringForKey:@"homePageViewCell_offical" withValue:nil withTable:@"Language"];
        
        describeImageView.frame = CGRectMake( originImageView.frame.size.width+trendsImageView.frame.size.width+20,140, 58, 18);
    }else{
        originImageView.hidden = YES;
        
        describeImageView.frame = CGRectMake(trendsImageView.frame.size.width+10,140, 58, 18);
    }
}
-(void)setTrends:(BOOL)isTrends
{
    if (isTrends == YES) {
        trendsLabel.text = [CTAppLanguage localizedStringForKey:@"homePageViewCell_dynamic" withValue:nil withTable:@"Language"];
    }else{
        trendsLabel.text = [CTAppLanguage localizedStringForKey:@"homePageViewCell_static" withValue:nil withTable:@"Language"];
    }
}




@end
